package June;

public class Test_19_1 {
    public static void main(String[] args) {
        Cale c1 = new Cale(10.1, 50.3);
        Cale c2 = new Cale(100.8, 0);
        System.out.println(c1.sum());
        System.out.println(c2.chengji());
        System.out.println(c1.cha());
        Double res = c2.shang();
        if (res != null) {
            System.out.println(c2.shang());
        } else {
            System.out.println("被除数不能为0");
        }
    }
}

// 编程创建一个Cale计算类，
// 在其中定义2个变量表示两个操作数，
// 定义四个方法实现求和、差、乘、商(要求除数为0的话，要提示)
// 并创建两个对象，分别测试
class Cale {
    double num1;
    double num2;
    public Cale(double num1, double num2) {
        this.num1 = num1;
        this.num2 = num2;
    }
    //求和
    public double sum() {
        return this.num1 + this.num2;
    }
    //求差
    public double cha() {
        return this.num1 - this.num2;
    }
    //求乘
    public double chengji() {
        return this.num1 * this.num2;
    }
    //求商
    public Double shang() {
        if (this.num2 != 0) {
            return this.num1 / this.num2;
        } else {
            return null;
        }
    }
}